package edu.hunau.cxb.controller;

import edu.hunau.cxb.pojo.Product;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @author hb
 * @create 2020-04-01 11:22
 */
@Controller
public class ThymeleafDemoController {

    @RequestMapping("/execute")
    public String execute(Map<String,Object> map){

        //绑定数据
        map.put("datas","你好，Thymeleaf!");

        return "hello";
    }

    @RequestMapping("/list")
    public String findProductList(Map<String,Object> map){
        List<Product> products = new ArrayList<>();
        products.add(new Product(1001,"哇哈哈",2.50, LocalDate.now(),true));
        products.add(new Product(1002,"格瓦斯",3.50, LocalDate.now(),true));
        products.add(new Product(1003,"盐汽水",5.50, LocalDate.now(),false));
        map.put("products",products);

        return "list";
    }


    @RequestMapping("/if")
    public String ifTestDemo(Map<String,Object> map){
      List<String> datas=new ArrayList<>();
        Collections.addAll(datas,"haoren","false","off","no","");
        map.put("datas",datas);
        return "if";
    }

    @RequestMapping("/text")
    public String textTestDemo(Map<String,Object> map){
        map.put("desc","春暖花开，<h1>马上就要开学啦!</h1>");
        map.put("username","<strong>好人</strong>");
        return "text";
    }
}
